Write-Host "=== 数据库问题诊断 ===" -ForegroundColor Green

Write-Host "`n1. 检查后端服务..." -ForegroundColor Yellow
try {
    $response = Invoke-RestMethod -Uri "http://localhost:5252/api/auth/validate" -Method GET -ErrorAction Stop
    Write-Host "✓ 后端服务正常运行" -ForegroundColor Green
} catch {
    Write-Host "✗ 后端服务连接失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n2. 测试登录..." -ForegroundColor Yellow
try {
    $loginData = @{
        username = "admin"
        password = "password"
    } | ConvertTo-Json
    
    $loginResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/auth/login" -Method POST -Body $loginData -ContentType "application/json"
    Write-Host "✓ 登录成功" -ForegroundColor Green
} catch {
    Write-Host "✗ 登录失败: $($_.Exception.Message)" -ForegroundColor Red
    Write-Host "`n可能的原因:" -ForegroundColor Yellow
    Write-Host "1. 数据库连接失败" -ForegroundColor White
    Write-Host "2. 数据库中没有用户数据" -ForegroundColor White
    Write-Host "3. 密码哈希不匹配" -ForegroundColor White
}

Write-Host "`n3. 解决方案:" -ForegroundColor Yellow
Write-Host "1. 检查PostgreSQL数据库连接" -ForegroundColor White
Write-Host "2. 执行数据库迁移: dotnet ef database update" -ForegroundColor White
Write-Host "3. 手动插入测试数据" -ForegroundColor White 